#!/bin/python3
# -*- coding: UTF-8
import sys
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.colors
import matplotlib.dates as mdates
from matplotlib.ticker import ScalarFormatter
from matplotlib.ticker import LogFormatter
from matplotlib.ticker import MultipleLocator
from matplotlib.ticker import FormatStrFormatter
from matplotlib.font_manager import findfont, FontProperties  
import matplotlib.font_manager as font_manager
import matplotlib.ticker as mtick
import seaborn as sns
from scipy.stats.mstats import gmean



def calculate_geomean(datay):
	print (datay)
	ret = gmean(datay)
	print (ret)
	return ret

# 读文件
def read_data(file_path):
	data = np.loadtxt(file_path,dtype=str,delimiter=' ')
	return data

def choose(data, x, col):
	return data[data[:, col] == x, 0:]

def filter(data, x):
	return data[data[:, 0] == x, 1:]

def uniqx(data):
	uniq_x = []
	for x in data[:, 0]:
		if x not in uniq_x:
			uniq_x.append(x)
	return np.array(uniq_x)

def avg_all(data, x):
	ret = np.average(data[:, 0] == x, axis = 0)
	return ret

filename = sys.argv[1]
data = read_data(filename)

# 获得所有lib名字(除去第一行)
libname = uniqx(data[1:])
print (libname)
# 获得所有bench 名字
# 计算n次执行结果的平均值和标准差
avg_result = []
for lib in libname:
	# 多次执行结果 计算平均值和标准差
	result_data = filter(data, lib)[:, :-1].astype(int)
	mdata = np.mean(result_data, axis=0)
	stddata = np.std(result_data, axis=0)
	# avg_result.append(np.array([lib, np.mean(result_data, axis=0).astype(str), np.std(result_data).astype(str)]))
	print ("%s " % lib, end="")
	for idx in range(0, len(mdata)):
		# print("%.3f ± %.3f " % (mdata[idx], stddata[idx]), end="")
		print("%.0f " % (mdata[idx]), end="") 
	print ("")


	# print("%s %.3f %.3f" % (lib, np.mean(result_data, axis=0), np.std(result_data, axis=0)))
avg_result = np.array(avg_result)
